package day2.cases

import scala.util.Random
// 样例主要用来做匹配
case class SubmitTask(id: String, name: String)

case class HeartBeat(time: Long)

case object CheckTimeOutTask  //为什么不能封装数据，因为它只有一份，如果别人要用只有把他给覆盖了。

object CaseDemo04 extends App{

  val arr = Array(CheckTimeOutTask, new HeartBeat(123), HeartBeat(88888), new HeartBeat(666), SubmitTask("0001", "task-0001")) //样例类，类名传参数就相当于new了

//  val a = CheckTimeOutTask
//  val b = CheckTimeOutTask

  val a = arr(Random.nextInt(arr.length))
  println(a)
  a match {
    case SubmitTask(id, name) => {
      println(s"$id, $name")
    }
    case HeartBeat(time) => {
      println(time)
    }
    case CheckTimeOutTask => {
      println("check")
    }
  }
}
